package com.dog.basics.service.mtkj.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dog.basics.bean.dto.admin.mtkj.WheelchairAddDto;
import com.dog.basics.bean.dto.admin.mtkj.WheelchairEditDto;
import com.dog.basics.bean.dto.admin.mtkj.WheelchairFromDto;
import com.dog.basics.bean.model.common.DogComPositioninfo;
import com.dog.basics.bean.model.mtkj.*;
import com.dog.basics.bean.vo.admin.mtkj.TjWheelchairVo;
import com.dog.basics.bean.vo.admin.mtkj.WheelchairVo;
import com.dog.basics.common.util.IPageVo;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.dao.common.DogComPositioninfoMapper;
import com.dog.basics.dao.mtkj.*;
import com.dog.basics.security.util.SecurityUtils;
import com.dog.basics.service.mtkj.IMtDeviceWheelchairService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 设备轮椅 服务实现类
 * </p>
 *
 * @author wph
 * @since 2020-09-29
 */
@Service
@AllArgsConstructor
public class MtDeviceWheelchairServiceImpl extends ServiceImpl<MtDeviceWheelchairMapper, MtDeviceWheelchair> implements IMtDeviceWheelchairService {
    private final DogComPositioninfoMapper dogComPositioninfoMapper;
    private final MtDeviceHospitalWheelchairMapper mtDeviceHospitalWheelchairMapper;
    private final MtDeviceHospitalMapper mtDeviceHospitalMapper;
    private final MtDeviceOrderMapper mtDeviceOrderMapper;
    private final MtDeviceLockPassMapper mtDeviceLockPassMapper;
    private final MtDeviceLockMapper mtDeviceLockMapper;

    /**
     * 分页的条件公用类
     *
     * @param name,mobile
     * @param hospitalIds
     */
    public List<Long> gethospitalIdsWhere(String name, Long id, List<Long> hospitalIds) {
        List<Long> collect = mtDeviceHospitalMapper.selectList(Wrappers.<MtDeviceHospital>lambdaQuery().eq(ObjectUtil.isNotNull(id), MtDeviceHospital::getId, id).like(StrUtil.isNotBlank(name), MtDeviceHospital::getHospitalName, name)).stream().map(e -> e.getId()).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect)) {
            hospitalIds = collect;
        } else {
            hospitalIds.add(-2L);
        }
        return hospitalIds;
    }

    /**
     * @Description: 分页设备轮椅
     * @Param: status
     * @return: IPage<WheelchairVo>
     * @Author: wph
     * @Date:
     */
/*    @Override
    public IPageVo<WheelchairVo> getPageList(PageParam page, WheelchairFromDto obj) {
        IPageVo<WheelchairVo> iPageVo = new IPageVo();
        //权限判断
        List<Long> id = CollUtil.newArrayList();
        if (SecurityUtils.getSysUser().getAccountType() == 2) {
            List<Long> hospitalIdss = mtDeviceHospitalMapper.selectList(Wrappers.<MtDeviceHospital>lambdaQuery().eq(ObjectUtil.isNotNull(obj.getHospitalId()), MtDeviceHospital::getId, obj.getHospitalId()).like(StrUtil.isNotBlank(obj.getHospitalName()), MtDeviceHospital::getHospitalName, obj.getHospitalName()).eq(MtDeviceHospital::getHospitalAgentUserId, SecurityUtils.getSysUser().getUserId())).stream().map(e -> e.getId()).collect(Collectors.toList());
            if (CollUtil.isEmpty(hospitalIdss)) {
                hospitalIdss.add(-2L);
            }
            id = mtDeviceHospitalWheelchairMapper.selectList(Wrappers.<MtDeviceHospitalWheelchair>lambdaQuery().in(MtDeviceHospitalWheelchair::getHospitalId, hospitalIdss)).stream().map(e -> e.getWheelchairId()).distinct().collect(Collectors.toList());
        } else {
            // 判断所属医院ID
            List<Long> hospitalIds = CollUtil.newArrayList();
            if (StrUtil.isNotBlank(obj.getHospitalName()) || ObjectUtil.isNotNull(obj.getHospitalId())) {
                hospitalIds = gethospitalIdsWhere(obj.getHospitalName(), obj.getHospitalId(), hospitalIds);
                //查询
                id = mtDeviceHospitalWheelchairMapper.selectList(Wrappers.<MtDeviceHospitalWheelchair>lambdaQuery().in(MtDeviceHospitalWheelchair::getHospitalId, hospitalIds)).stream().map(e -> e.getWheelchairId()).distinct().collect(Collectors.toList());
            }
        }
        this.page(page, new LambdaQueryWrapper<MtDeviceWheelchair>()
                .in(CollUtil.isNotEmpty(id), MtDeviceWheelchair::getId, id)
                .like(StrUtil.isNotBlank(obj.getWheeCode()), MtDeviceWheelchair::getWheeCode, obj.getWheeCode())
                .like(StrUtil.isNotBlank(obj.getWheeName()), MtDeviceWheelchair::getWheeName, obj.getWheeName())
                .like(StrUtil.isNotBlank(obj.getWheePosition()), MtDeviceWheelchair::getWheePosition, obj.getWheePosition())
                .like(StrUtil.isNotBlank(obj.getDetailedAddress()), MtDeviceWheelchair::getDetailedAddress, obj.getDetailedAddress())
                .eq(ObjectUtil.isNotNull(obj.getWheeType()), MtDeviceWheelchair::getWheeType, obj.getWheeType())
                .eq(ObjectUtil.isNotNull(obj.getWheeState()), MtDeviceWheelchair::getWheeState, obj.getWheeState())
                .eq(ObjectUtil.isNotNull(obj.getProvinceId()), MtDeviceWheelchair::getProvinceId, obj.getProvinceId())
                .eq(ObjectUtil.isNotNull(obj.getCityId()), MtDeviceWheelchair::getCityId, obj.getCityId())
                .eq(ObjectUtil.isNotNull(obj.getAreaId()), MtDeviceWheelchair::getAreaId, obj.getAreaId())
                .eq(ObjectUtil.isNotNull(obj.getUseState()), MtDeviceWheelchair::getUseState, obj.getUseState())
                .between(ObjectUtil.isNotNull(obj.getStartTime()) && ObjectUtil.isNotNull(obj.getEndTime()), MtDeviceWheelchair::getWheeUseTime, obj.getStartTime(), obj.getEndTime())
                .orderBy(Boolean.TRUE, obj.getIsOrderByAvg(), MtDeviceWheelchair::getCreateTime));
        List<MtDeviceWheelchair> records = page.getRecords();
        page.setRecords(records.stream().map(e -> {
            WheelchairVo newsVo = new WheelchairVo();
            BeanUtil.copyProperties(e, newsVo);
            //查询
            DogComPositioninfo province = dogComPositioninfoMapper.selectById(e.getProvinceId());
            DogComPositioninfo city = dogComPositioninfoMapper.selectById(e.getCityId());
            DogComPositioninfo area = dogComPositioninfoMapper.selectById(e.getAreaId());
            newsVo.setProvinceName(ObjectUtil.isNotNull(province) ? province.getAreaName() : "");
            newsVo.setCityName(ObjectUtil.isNotNull(city) ? city.getAreaName() : "");
            newsVo.setAreaName(ObjectUtil.isNotNull(area) ? area.getAreaName() : "");
            List<MtDeviceHospitalWheelchair> list = mtDeviceHospitalWheelchairMapper.selectList(Wrappers.<MtDeviceHospitalWheelchair>lambdaQuery().eq(MtDeviceHospitalWheelchair::getWheelchairId, e.getId()).orderByDesc(MtDeviceHospitalWheelchair::getCreateTime));
            if (CollUtil.isNotEmpty(list)) {
                MtDeviceHospital mtDeviceHospital = mtDeviceHospitalMapper.selectById(list.get(0).getHospitalId());
                newsVo.setHospitalId(mtDeviceHospital.getId());
                newsVo.setHospitalName(ObjectUtil.isNotNull(mtDeviceHospital) ? mtDeviceHospital.getHospitalName() : "");
                newsVo.setType(1);
            } else {
                newsVo.setType(0);
            }
            //查询卡所在的主板位置
            List<MtDeviceLockPass> lockPassList = mtDeviceLockPassMapper.selectList(Wrappers.<MtDeviceLockPass>lambdaQuery().eq(MtDeviceLockPass::getWheeId, e.getId()).orderByDesc(MtDeviceLockPass::getCreateTime).last(" limit 1"));
            if (CollUtil.isNotEmpty(lockPassList)) {
                MtDeviceLock mtDeviceLock = mtDeviceLockMapper.selectById(lockPassList.get(0).getLockId());
                newsVo.setAddress(ObjectUtil.isNotNull(mtDeviceLock) ? mtDeviceLock.getDevName() : "");
            }
            newsVo.setSumUserTime(mtDeviceOrderMapper.getSumUserTime(e.getId()));
            newsVo.setSumUserMonthTime(mtDeviceOrderMapper.getSumUserMonthTime(e.getId(), DateUtil.beginOfMonth(DateUtil.date()).getTime() / 1000L, DateUtil.endOfMonth(DateUtil.date()).getTime() / 1000L));
            return newsVo;
        }).collect(Collectors.toList()));
        iPageVo.setIPage(page);
        iPageVo.setSubtotal(this.tjObj());
        return iPageVo;
    }*/
    @Override
    public IPageVo<WheelchairVo> getPageList(PageParam page, WheelchairFromDto obj) {
        IPageVo<WheelchairVo> iPageVo = new IPageVo();
        //权限判断
        List<Long> id = CollUtil.newArrayList();
        if (SecurityUtils.getSysUser().getAccountType() == 2) {
            List<Long> hospitalIdss = mtDeviceHospitalMapper.selectList(Wrappers.<MtDeviceHospital>lambdaQuery().eq(ObjectUtil.isNotNull(obj.getHospitalId()), MtDeviceHospital::getId, obj.getHospitalId()).like(StrUtil.isNotBlank(obj.getHospitalName()), MtDeviceHospital::getHospitalName, obj.getHospitalName()).eq(MtDeviceHospital::getHospitalAgentUserId, SecurityUtils.getSysUser().getUserId())).stream().map(e -> e.getId()).collect(Collectors.toList());
            if (CollUtil.isEmpty(hospitalIdss)) {
                hospitalIdss.add(-2L);
            }
            id = mtDeviceHospitalWheelchairMapper.selectList(Wrappers.<MtDeviceHospitalWheelchair>lambdaQuery().in(MtDeviceHospitalWheelchair::getHospitalId, hospitalIdss)).stream().map(e -> e.getWheelchairId()).distinct().collect(Collectors.toList());
        } else {
            // 判断所属医院ID
            List<Long> hospitalIds = CollUtil.newArrayList();
            if (StrUtil.isNotBlank(obj.getHospitalName()) || ObjectUtil.isNotNull(obj.getHospitalId())) {
                hospitalIds = gethospitalIdsWhere(obj.getHospitalName(), obj.getHospitalId(), hospitalIds);
                //查询
                id = mtDeviceHospitalWheelchairMapper.selectList(Wrappers.<MtDeviceHospitalWheelchair>lambdaQuery().in(MtDeviceHospitalWheelchair::getHospitalId, hospitalIds)).stream().map(e -> e.getWheelchairId()).distinct().collect(Collectors.toList());
            }
        }
        //根据条件查询设备的ID
        List<Long> ids = this.list(Wrappers.<MtDeviceWheelchair>lambdaQuery()
                .in(CollUtil.isNotEmpty(id), MtDeviceWheelchair::getId, id)
                .like(StrUtil.isNotBlank(obj.getWheeCode()), MtDeviceWheelchair::getWheeCode, obj.getWheeCode())
                .like(StrUtil.isNotBlank(obj.getWheeName()), MtDeviceWheelchair::getWheeName, obj.getWheeName())
                .like(StrUtil.isNotBlank(obj.getWheePosition()), MtDeviceWheelchair::getWheePosition, obj.getWheePosition())
                .like(StrUtil.isNotBlank(obj.getDetailedAddress()), MtDeviceWheelchair::getDetailedAddress, obj.getDetailedAddress())
                .eq(ObjectUtil.isNotNull(obj.getWheeType()), MtDeviceWheelchair::getWheeType, obj.getWheeType())
                .eq(ObjectUtil.isNotNull(obj.getWheeState()), MtDeviceWheelchair::getWheeState, obj.getWheeState())
                .eq(ObjectUtil.isNotNull(obj.getProvinceId()), MtDeviceWheelchair::getProvinceId, obj.getProvinceId())
                .eq(ObjectUtil.isNotNull(obj.getCityId()), MtDeviceWheelchair::getCityId, obj.getCityId())
                .eq(ObjectUtil.isNotNull(obj.getAreaId()), MtDeviceWheelchair::getAreaId, obj.getAreaId())
                .eq(ObjectUtil.isNotNull(obj.getUseState()), MtDeviceWheelchair::getUseState, obj.getUseState())
                .between(ObjectUtil.isNotNull(obj.getStartTime()) && ObjectUtil.isNotNull(obj.getEndTime()), MtDeviceWheelchair::getWheeUseTime, obj.getStartTime(), obj.getEndTime())
                .orderBy(Boolean.TRUE, obj.getIsOrderByAvg(), MtDeviceWheelchair::getCreateTime)).stream().map(e -> e.getId()).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(ids)) {
            IPage iPage = this.baseMapper.getPageList(page,DateUtil.beginOfMonth(DateUtil.date()).getTime() / 1000L,DateUtil.endOfMonth(DateUtil.date()).getTime() / 1000L, ids,obj.getAllTimeFlage());
            List<WheelchairVo> records = iPage.getRecords();
            page.setRecords(records.stream().map(e -> {
                //查询
                DogComPositioninfo province = dogComPositioninfoMapper.selectById(e.getProvinceId());
                DogComPositioninfo city = dogComPositioninfoMapper.selectById(e.getCityId());
                DogComPositioninfo area = dogComPositioninfoMapper.selectById(e.getAreaId());
                e.setProvinceName(ObjectUtil.isNotNull(province) ? province.getAreaName() : "");
                e.setCityName(ObjectUtil.isNotNull(city) ? city.getAreaName() : "");
                e.setAreaName(ObjectUtil.isNotNull(area) ? area.getAreaName() : "");
                List<MtDeviceHospitalWheelchair> list = mtDeviceHospitalWheelchairMapper.selectList(Wrappers.<MtDeviceHospitalWheelchair>lambdaQuery().eq(MtDeviceHospitalWheelchair::getWheelchairId, e.getId()).orderByDesc(MtDeviceHospitalWheelchair::getCreateTime));
                if (CollUtil.isNotEmpty(list)) {
                    MtDeviceHospital mtDeviceHospital = mtDeviceHospitalMapper.selectById(list.get(0).getHospitalId());
                    e.setHospitalId(mtDeviceHospital.getId());
                    e.setHospitalName(ObjectUtil.isNotNull(mtDeviceHospital) ? mtDeviceHospital.getHospitalName() : "");
                    e.setType(1);
                } else {
                    e.setType(0);
                }
                //查询卡所在的主板位置
                List<MtDeviceLockPass> lockPassList = mtDeviceLockPassMapper.selectList(Wrappers.<MtDeviceLockPass>lambdaQuery().eq(MtDeviceLockPass::getWheeId, e.getId()).orderByDesc(MtDeviceLockPass::getCreateTime).last(" limit 1"));
                if (CollUtil.isNotEmpty(lockPassList)) {
                    MtDeviceLock mtDeviceLock = mtDeviceLockMapper.selectById(lockPassList.get(0).getLockId());
                    e.setAddress(ObjectUtil.isNotNull(mtDeviceLock) ? mtDeviceLock.getDevName() : "");
                }
                return e;
            }).collect(Collectors.toList()));
            iPageVo.setIPage(page);
            iPageVo.setSubtotal(this.tjObj());
            return iPageVo;
        } else {
            return iPageVo;
        }

    }

    /**
     * @Description: 轮椅数据统计
     * @Param:
     * @return:
     * @Author: wph
     * @Date: 2020/10/14 0014
     */
    public TjWheelchairVo tjObj() {
        Integer kxWheelchair = this.count(Wrappers.<MtDeviceWheelchair>lambdaQuery().eq(MtDeviceWheelchair::getWheeState, 1));
        Integer useWheelchair = this.count(Wrappers.<MtDeviceWheelchair>lambdaQuery().eq(MtDeviceWheelchair::getWheeState, 2));
        Integer noBdWheelchair = this.count(Wrappers.<MtDeviceWheelchair>lambdaQuery().eq(MtDeviceWheelchair::getWheeState, 0));
        Integer badWheelchair = this.count(Wrappers.<MtDeviceWheelchair>lambdaQuery().eq(MtDeviceWheelchair::getWheeState, 3));
        Integer sumWheelchair = this.count();
        TjWheelchairVo tjWheelchairVo = new TjWheelchairVo();
        tjWheelchairVo.setKxWheelchair(kxWheelchair);
        tjWheelchairVo.setUseWheelchair(useWheelchair);
        tjWheelchairVo.setNoBdWheelchair(noBdWheelchair);
        tjWheelchairVo.setBadWheelchair(badWheelchair);
        tjWheelchairVo.setSumWheelchair(sumWheelchair);
        if (sumWheelchair <= 0) {
            tjWheelchairVo.setKxWheelchairBl("0");
            tjWheelchairVo.setUseWheelchairBl("0");
            tjWheelchairVo.setNoBdWheelchairBl("0");
            tjWheelchairVo.setBadWheelchairBl("0");
            tjWheelchairVo.setSumWheelchairBl("0");
        } else {
            tjWheelchairVo.setKxWheelchairBl(BigDecimal.valueOf(kxWheelchair).divide(BigDecimal.valueOf(sumWheelchair), 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%");
            tjWheelchairVo.setUseWheelchairBl(BigDecimal.valueOf(useWheelchair).divide(BigDecimal.valueOf(sumWheelchair), 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%");
            tjWheelchairVo.setNoBdWheelchairBl(BigDecimal.valueOf(noBdWheelchair).divide(BigDecimal.valueOf(sumWheelchair), 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%");
            tjWheelchairVo.setBadWheelchairBl(BigDecimal.valueOf(badWheelchair).divide(BigDecimal.valueOf(sumWheelchair), 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%");
            tjWheelchairVo.setSumWheelchairBl("100%");
        }

        return tjWheelchairVo;
    }

    /**
     * @Description: 增加设备轮椅
     * @Param: obj
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveObj(WheelchairAddDto obj) {
        Validator.validateFalse(Validator.equal(obj.getWheeCode(), "0000000000"), "设备编号不能为0000000000");
        //判断编号是否存在
        List<MtDeviceWheelchair> list = this.list(Wrappers.<MtDeviceWheelchair>lambdaQuery().eq(MtDeviceWheelchair::getWheeCode, obj.getWheeCode()));
        Validator.validateFalse(CollUtil.isNotEmpty(list), "该编号已经存在!");
/*        DogComPositioninfo province = dogComPositioninfoMapper.selectById(obj.getProvinceId());
        Validator.validateNotNull(province, "省不存在!");
        DogComPositioninfo city = dogComPositioninfoMapper.selectById(obj.getCityId());
        Validator.validateNotNull(city, "市不存在!");
        DogComPositioninfo area = dogComPositioninfoMapper.selectById(obj.getAreaId());
        Validator.validateNotNull(area, "区不存在!");*/
        MtDeviceWheelchair dogNews = new MtDeviceWheelchair();
        BeanUtil.copyProperties(obj, dogNews);
        dogNews.setCreateTime(DateUtil.currentSeconds());
        dogNews.setCreateBy(SecurityUtils.getSysUser().getUserId());
        Validator.validateTrue(this.save(dogNews), "数据保存失败!");
        return Boolean.TRUE;
    }

    /**
     * @Description: 修改设备轮椅
     * @Param: obj
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean editObj(WheelchairEditDto obj) {
        Validator.validateFalse(Validator.equal(obj.getWheeCode(), "0000000000"), "设备编号不能为0000000000");
        MtDeviceWheelchair dogNews = this.getById(obj.getId());
        Validator.validateNotNull(dogNews, "无此数据!");
        //判断编号是否存在
        List<MtDeviceWheelchair> list = this.list(Wrappers.<MtDeviceWheelchair>lambdaQuery().ne(MtDeviceWheelchair::getId, obj.getId()).eq(MtDeviceWheelchair::getWheeCode, obj.getWheeCode()));
        Validator.validateFalse(CollUtil.isNotEmpty(list), "该编号已经存在!");
/*        DogComPositioninfo province = dogComPositioninfoMapper.selectById(obj.getProvinceId());
        Validator.validateNotNull(province, "省不存在!");
        DogComPositioninfo city = dogComPositioninfoMapper.selectById(obj.getCityId());
        Validator.validateNotNull(city, "市不存在!");
        DogComPositioninfo area = dogComPositioninfoMapper.selectById(obj.getAreaId());
        Validator.validateNotNull(area, "区不存在!");*/
        BeanUtil.copyProperties(obj, dogNews);
        dogNews.setUpdateTime(DateUtil.currentSeconds());
        dogNews.setUpdateBy(SecurityUtils.getSysUser().getUserId());
        Validator.validateTrue(this.updateById(dogNews), "修改数据失败!");
        return Boolean.TRUE;
    }

    /**
     * @Description: 删除设备轮椅
     * @Param: ids
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteObj(Long id) {
        MtDeviceWheelchair dogNews = this.getById(id);
        Validator.validateNotNull(dogNews, "无此数据!");
        List<MtDeviceHospitalWheelchair> mtDeviceWheelchairWheelchairList = mtDeviceHospitalWheelchairMapper.selectList(Wrappers.<MtDeviceHospitalWheelchair>lambdaQuery().eq(MtDeviceHospitalWheelchair::getWheelchairId, id));
        Validator.validateFalse(CollUtil.isNotEmpty(mtDeviceWheelchairWheelchairList), "医院下有轮椅无法删除!");
        List<MtDeviceLockPass> mtDeviceLockPassList = mtDeviceLockPassMapper.selectList(Wrappers.<MtDeviceLockPass>lambdaQuery().eq(MtDeviceLockPass::getWheeId, id));
        if (CollUtil.isNotEmpty(mtDeviceLockPassList)) {
            MtDeviceLockPass mtDeviceLockPass = mtDeviceLockPassList.get(0);
            MtDeviceLock mtDeviceLock = mtDeviceLockMapper.selectById(mtDeviceLockPass.getLockId());
            Validator.validateTrue(Boolean.FALSE, StrUtil.format("轮椅绑定在:{},通道为:{},不能删除", ObjectUtil.isNotNull(mtDeviceLock) ? mtDeviceLock.getDevName() : "", mtDeviceLockPass.getPassNum()));

        }
        Validator.validateTrue(this.removeById(id), "数据删除失败!");
        return Boolean.TRUE;
    }

    /**
     * @Description: 开启关闭设备
     * @Param: WheelchairEditDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean editUse(Long id) {
        MtDeviceWheelchair dogNews = this.getById(id);
        Validator.validateNotNull(dogNews, "无此数据!");
        dogNews.setUseState(dogNews.getUseState() == 0 ? 1 : 0);
        dogNews.setUpdateTime(DateUtil.currentSeconds());
        dogNews.setUpdateBy(SecurityUtils.getSysUser().getUserId());
        Validator.validateTrue(this.updateById(dogNews), "修改数据失败!");
        return Boolean.TRUE;
    }
}
